<?php session_start();?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <link href="style3.css" rel="stylesheet" type="text/css" />
    </head>
    <form method ="post" >
<!--        <input style= "margin-left: 0px; top: 225px; position: relative " name="subscribe" type="submit" value="subscribe" /> -->
    </form>
</html>
<?php
require_once "functions.php";
//connect to the database
$member_id=$_SESSION['member_id'];
$result=mysql_query("SELECT conference_id, long_name FROM conference") Or die(mysql_error());
// save all conferences in array
//$conferences = $_POST['$result'];
if(!mysql_num_rows($result))
{ // check if the query returned output or not
    echo '<script>',
    'alert("There are no conferences");',
    '</script>';
}
//table containing all the conferences available
else
{
    echo '<table width="100%">
    <tr>
    <td><b>' . $lang['conf'] . '</b>
    </td>
    </tr>';
//redirect to the conference page
//while ($row = mysql_fetch_assoc($result)) {
//    echo//"<tr>
//          //<td><input type=\"checkbox\" name=\"conf[]\" value=\"{$row['conference_id']}\"></td>\n
//	  //<td>{$row['long_name']}</td>
//	  //<td><a href='conferencePage.php?conference_id={$row['conference_id']}'>go to Conference</a </td>
//	  </tr>";
//}

    for($i=0; $i < $row=mysql_fetch_assoc($result); ++$i)
    {
        ?>
        <form method="post" action="">
            <?php
            $long=formatText_safe($row['long_name']);
            print "<tr>\n";
            print "<td><input type=\"checkbox\" name=\"conf[]\" value=\"{$row['conference_id']}\"></td>\n";
            echo "<td><width=\"0%\" height=\"0\" style=\"display:none\" value=\"\"</td>\n";
            echo "<td>{$long}</td>\n"; // print names
            echo "
	            <td><a href='conferencePage.php?conference_id={$row['conference_id']}'>" . $lang['goConf'] . "</a </td>";
        }


        if(isset($_POST['subscribe']))
        {

            //an array is created to store all the values of the checkboxes that were clicked
            $num_conf=mysql_real_escape_string($_POST['conf']);
            //a variable is initialized to store the length of the array as an integer
            $n=count($num_conf);
            //loops on all the values in the array
            for($i=0; $i < $n; $i++)
            {
                //retrieves the value in the array at position i and stores it in a variable
                $confid=mysql_real_escape_string($num_conf[$i]);
                //check whether this member is subscribed in this conference as a reviewer or not
                $check_subscriber=mysql_query("SELECT* FROM Member_Privileges
                 WHERE member_id ='$member_id' AND privileges_id ='4' AND conference_id ='$confid'") or die(mysql_error());

                $row=mysql_fetch_assoc($check_subscriber);
                //if the rows are greater than one then he is a subscriber  in this conference
                if($row > 1)
                {
                    echo '<script>',
                    'alert("your are already subscriber in this conference");',
                    '</script>';
                }
                else
                {
                    //executes a query to insert the values of the ids of the checked conferences into the
                    //table member_privileges with the id of the conference
                    mysql_query("INSERT INTO member_privileges (member_id, privileges_id ,conference_id)
                        VALUES ('$member_id', '4', '$confid')") or die("error");
                    echo '<script>',
                    'alert("your action done correctly");',
                    '</script>';
                }
            }
        }
        ?>
        <tr><td><input type="submit" name="subscribe" value="<?php echo $lang['sub'];?>"></td></tr>
        <br>
        <?
    }
    ?>
